# -*- coding: utf-8 -*-
"""
-------------------------------------------------
# @Project  :alien_invasion
# @File     :alien_invasion.py
# @Date     :2021/5/30 16:34
# @Author   :逆羽
# @Email    :xiehouxiayu@163.com
# @IDE      :PyCharm
-------------------------------------------------
"""
import pygame
from pygame.sprite import Group

from settings import Settings
from ship import Ship
import game_functions as gf
from game_stats import GameStats
from button import Button
from scoreboard import Scoreboard


def run_game():
    # 初始化游戏并创建一个屏幕对象
    pygame.init()
    # 初始化设置
    ai_settings = Settings()
    screen = pygame.display.set_mode(
        (ai_settings.screen_width, ai_settings.screen_height))
    pygame.display.set_caption("Alien Invasion")
    # 创建play按钮
    play_button = Button(ai_settings, screen, 'START')
    # 创建一个用于储存游戏统计信息的实例
    stats = GameStats(ai_settings)
    score_board = Scoreboard(ai_settings, screen, stats)
    # 创建一艘飞船和一个外星人
    ship = Ship(ai_settings, screen)
    # 创建一个用于存储子弹的编组
    bullets = Group()
    aliens = Group()
    # print(bullets)
    gf.create_fleet(ai_settings, screen, ship, aliens)

    # 开始游戏的主循环
    while True:
        gf.check_event(ship, ai_settings, screen, bullets, stats, play_button, aliens, score_board)
        if stats.game_active:
            ship.update()
            gf.update_bullets(bullets, aliens, ai_settings, screen, ship, stats, score_board)
            gf.update_aliens(ai_settings, aliens, ship, stats, screen, bullets, score_board)
        gf.update_screen(ai_settings, screen, ship, aliens, bullets, stats, play_button, score_board)


run_game()
